package core;

import java.util.ArrayList;

public class MaterialLib
{
	private static ArrayList<Material> materials;
	
	public static boolean addMaterial(Material mat)
	{
		if (materials == null)
			materials = new ArrayList<Material>();
		if (!materialExists(mat.name))
		{
			materials.add(mat);
			return true;
		}
		return false;
	}
	
	private static boolean materialExists(String name)
	{
		if (materials == null)
			return false;
		for (Material m : materials)
		{
			String n = m.name.trim();
			if (n.equalsIgnoreCase(name.trim()))
				return true;
		}
		return false;
	}
	
	public static Material getMaterial(String name)
	{
		if (materials == null)
			return null;
		for (Material m : materials)
		{
			String n = m.name.trim();
			if (n.equalsIgnoreCase(name.trim()))
				return m;
		}
		return null;
	}
	
	public static boolean removeMaterial(String name)
	{
		if (materials == null)
			return false;
		for (int i = 0; i < materials.size(); i++)
		{
			Material m = materials.get(i);
			String n = m.name.trim();
			if (n.equalsIgnoreCase(name.trim()))
			{
				materials.remove(i);
				return true;
			}
		}
		return false;
	}
}
